package com.example.mapp;

import com.example.entity.SpotCheckPlan;
import com.example.entity.SpotObjectCensus;
import com.example.entity.SpotObjectPlan;
import com.example.mapp.buildSql.SpotCheckPlanMappSql;
import com.example.mapp.buildSql.SpotObjectPlanMappSql;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 实施对象
 */
@Mapper
public interface SpotObjectPlanMapp {

    //通过id查询SQL语句
    @SelectProvider(type = SpotObjectPlanMappSql.class,method = "findlists")
    public List<SpotObjectPlan> findList(SpotObjectPlan spotObjectPlan) throws Exception;

    // 新增数据
    @Insert(" insert into spot_object_plan (plan_id,implement_object,implement_object_id,head_man,create_by,create_date,del_flag,check_record )" +
            "value " +
            "(#{planId},#{implementObject},#{implementObjectId},#{headMan},#{createBy},#{createDate},#{delFlag},#{checkRecord})")
    public void insert(SpotObjectPlan spotObjectPlan) throws Exception;

    // 修改数据
    @Update("update spot_object_plan set check_man=#{checkMan},user_id=#{userId} where id=#{id}")
    public void update(SpotObjectPlan spotObjectPlan) throws Exception;

    // 删除数据
    @Update("update spot_object_plan set del_flag='0' where id=#{id}")
    public void delete(String id) throws Exception;

    // 通过计划Id删除
    @Delete("delete from spot_object_plan where plan_id=#{planId}")
    public void deleteByPlanId(Long id) throws Exception;

    // 查询维保记录App
    @SelectProvider(type = SpotObjectPlanMappSql.class,method = "findRecordApp")
    List<Map<String, Object>> findRecordApp(SpotObjectPlan spotObjectPlan);

    //
    @SelectProvider(type = SpotObjectPlanMappSql.class,method = "spotObjectCensus")
    List<Map<String, Object>> spotObjectCensus(Map map);

    // App端完成之后，修改检查标志
    @Update("update spot_object_plan set check_record=#{checkRecord} where id=#{id}")
    public void updateCheckRecord(SpotObjectPlan spotObjectPlan) throws Exception;

    // App端查看已经完成检查项
    @SelectProvider(type = SpotObjectPlanMappSql.class,method = "getFinishItem")
    List<Map<String, Object>> getFinishItem(Map map);

    // web端获取导出数据
    @SelectProvider(type = SpotObjectPlanMappSql.class,method = "findExcelData")
    List<HashMap<String, Object>> findExcelData(SpotObjectCensus spotObjectCensus);

    @Select("select check_item_name as 'checkItemName'," +
            " (case when check_record = '1' then '不正常' when check_record = '0' then '正常' when check_record = '2' then '无此项' end) as 'checkRecord'," +
            "pic_url as 'picUrl'," +
            "remarkes as 'remarkes'," +
            "create_date as 'createDate' from spot_object_census where del_flag='1' and elevator_id=#{elevatorId} and plan_id=#{planId}  and implement_object=#{implementObject} and check_man=#{checkMan}")
    List<Map<String, Object>> queryPlanDetails(SpotObjectCensus spotObjectCensus);

    @Select("select us.check_item_name as 'checkItemName'," +
            " (case when us.check_record = '1' then '否' when us.check_record = '0' then '是' when us.check_record = '2' then '无此项' end) as 'checkRecord'," +
            "us.opinion as 'opinion'," +
            "us.remarkes as 'remarkes'," +
            "us.result_evaluate as 'resultEvaluate'," +
            "us.implement_object as 'implement_object'," +
            "us.check_man as 'check_man'," +
            " (case when it.ext2 !='null' then it.ext2 else '自定义项目' end )  as 'checkItemExplain'," +
            " us.create_date as 'createDate' from spot_object_census us  " +
            " left join check_item it ON  it.id=us.check_item_id " +
            " where us.del_flag='1' and us.elevator_id=#{elevatorId} and us.plan_id=#{planId}  and us.implement_object=#{implementObject} and us.check_man=#{checkMan}")
    List<SpotObjectCensus> exportExcelClown(SpotObjectCensus spotObjectCensus);
}
